package main

import (
	"fmt"
	"io/ioutil"
)

func main() {
	const filename = "abc.txt"
	//if
	if contents, err := readFile(filename); err != nil {
		fmt.Print(err)
	} else {
		fmt.Printf("%s\n", contents)
	}

	//switch
	res := switchDemo(31, 15, "/")
	fmt.Println(res)
}

func readFile(filename string) ([]byte, error) {
	return ioutil.ReadFile(filename)
}

func switchDemo(a, b int, op string) int {
	var result int
	switch op {
	case "+":
		result = a + b
	case "-":
		result = a - b
	case "*":
		result = a * b
	case "/":
		result = a / b
	default:
		//panic("两个异常")
	}
	return result

	// switch会自动break,除非使用了fallthrough
}
